package com.xieyong.leetcode;

import java.util.HashMap;
import java.util.Map;

public class Leetcode3442 {
    public static void main(String[] args) {
        Leetcode3442 leetcode3442 = new Leetcode3442();
        String s = "aaaaabbc";
        int i = leetcode3442.maxDifference(s);
        System.out.println(i);
    }


    public int maxDifference(String s) {
        Map<Character, Integer> map = new HashMap<>();
        for (char c : s.toCharArray()) {
            map.put(c, map.getOrDefault(c, 0) + 1);
        }
        int maxcount = 0;
        int mincount = Integer.MAX_VALUE;
        for (char c : map.keySet()) {
            int count = map.get(c);
            if (count % 2 != 0 && count >= maxcount) {
                maxcount = count;
            }
            if (count % 2 == 0 && count <= mincount) {
                mincount = count;
            }
        }
        return maxcount - mincount;
    }
}
